<?php

/**
 *	frontend module for module upload
 *	this module enables the user to add content (as in files) to a website
 *
 *	@author		pieter van peteghem <pieter@onedotonly.be>
 *	@date		9 march 2011
 */

class MediaUpload extends MOD {


	/**
	 *	constructor
	 *	add vars before parsing module
	 *	@param		array
	 */
 	function __construct( $vars ) {

		$this->_addvars( $vars );
		$this->_ref();
	}
	

	/**
	 *	output
	 *	defines subtype of module
	 */
	function output() {
	
		if( $this->action )
			$result = $this->{ "filter_" . $this->action }();

		$this->addclass( $this->action );

		if( $result && is_array( $result ))
			$result = implode( "\n", $result );
			
		if( $result )
			return $this->parse( $result ) . $this->render_js();

	}
	
	
	/**
	 *	dropper
	 *	frontend module that allows html5 drop file functionalities
	 */
	public function filter_drop() {
		global $Object;
		
		$res = '<div id="drop-area" class="dropper"><span class="note">' . translate( 'sleep uw foto hier' ) . '<span></div>';

		$this->js = '
			var mod = new MediaUpload( ' . json_encode( array_merge( array( 'objtype' => $Object->type, 'objid' => $Object->id ), (array) $this->vars )) . ' );
		';
		return $res;
		
	}
	
	
	public function ajax_upload() {
	
		echo 'foof';
	}
}
